package ltd.followkba.page;

import android.view.View;
import android.widget.ImageView;

import com.kcbsdk.EventHandler;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import ltd.advskin.MRAM;
import ltd.advskin.base.BasePage;
import ltd.advskin.base.KcListener;
import ltd.advskin.base.KcNoneListener;
import ltd.advskin.view.KcBannerView;
import ltd.advskin.view.KcBtnProgress;
import ltd.advskin.view.KcIndicatorView;
import ltd.followkba.MAPP;
import ltd.followkba.R;
import main.MAPI;

import static ltd.advskin.MSKIN.MSTRING;
import static main.MAPI.mMyWorks;

public class TipsPage extends BasePage {
    private KcBannerView kbvTips;
    private KcIndicatorView kivTips;
    private KcBtnProgress kbpTips;

    private int[] tabDrawable;
    private long gTick;
    private Timer mTimer;

    // 所有的页面都接受同样的方式打开LOG
    public static boolean logEnable;

    public void MLOG(String text) {
        if (logEnable) {
            MSTRING(MAPI.GET_LOG_NAME(this) + text);
        }
    }

    @Override
    public void onInitView() {                       // 使用者需要继承，初始化页面控件等显示
        setLayout(R.layout.page_tips);

        kbvTips = findViewById(R.id.kbvTips);
        kivTips = findViewById(R.id.kivTips);
        kbpTips = findViewById(R.id.kbpTips);
        kbvTips.initView(0, kivTips, new KcListener() {
            @Override
            public void onMessage(Object object) {
                gTick = System.currentTimeMillis();
                if (object instanceof Integer) {
                    int type = (int) object;
                    if (type == (tabDrawable.length-1)) {
                        kivTips.setVisibility(View.GONE);
                        kbpTips.setVisibility(View.VISIBLE);
                        kbpTips.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                setClose();
                            }
                        });
                    } else {
                        kivTips.setVisibility(View.VISIBLE);
                        kbpTips.setVisibility(View.GONE);
                    }
                }
            }
        });
        gTick = System.currentTimeMillis();
        mTimer = new Timer();
        mTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                MRAM.mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        MLOG(String.format("TipsPageA c %s", System.currentTimeMillis()-gTick));
                        if (gTick != 0 && (System.currentTimeMillis()-gTick ) > 8000){
                            MLOG(String.format("TipsPageA b %s", gTick));
                            onFinish();
                        }
                    }
                });
            }
        }, 1000, 1000);
        tabDrawable = new int[]{R.drawable.tips0, R.drawable.tips1, R.drawable.tips2, R.drawable.tips3, R.drawable.tips4, R.drawable.tips5,};
        kbvTips.setBitmap(tabDrawable);
        MLOG(String.format("TipsPageA "));
    }

    @Override
    public void onInitData(){                                                                       // onInitView结束，开始加载数据
        showInfo();
    }
    @Override
    public void onFinish() {       // 使用者选择性继承，用户按了后退键，不继承就直接关闭了
        MLOG(String.format("TipsPageA a"));
        mTimer.cancel();
        MLOG(String.format("TipsPageA d"));
        setClose();
    }
    private void showInfo() {

    }
}